import scala.annotation.tailrec

object FirstDemo {

  def main(args: Array[String]): Unit = {
    var x = 0
    MyWhile(x < 10) {
      x += 1;
      println(x)
    }
  }

  /**
   * 尾递优化
   */
  @tailrec
  def MyWhile(condition: => Boolean)(block: => Unit): Unit = {
    if (condition) {
      block
      MyWhile(condition)(block)
    }
  }

}


class Student {

  var name: String = _
  var age: Int = _

  // 构造方法的格式 注意和java的区别
  def this(name: String) = {
    // 辅助构造器必须调用柱构造器
    this()
    this.name = name;
  }

  def this(age: Int, name: String) = {
    // 借用上面的构造辅助构造器已经调用了主构造器
    this(name)
    this.age = age
  }

}